<template>
  <div>
    <ul>
      <li v-for="(item, i) in list" :key="item">
        <span>{{ item }}</span>
        <button @click="del(i)">删除</button>
      </li>
    </ul>

    <button @click="btn">添加</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [1, 1, 1],
    }
  },
  methods: {
    btn() {
      //  产生随机数
      this.list.push(Math.floor(Math.random() * 20))
    },
    del(index) {
      this.list.splice(index, 1)
    },
  },
}
</script>

<style></style>
